import address from '../address';
let token = '' || localStorage.getItem('token');

//获取审核列表
export const getExamineList = () =>{
    return (dispatch)=>{
        let url = address + '/userstep/reviewing';
        fetch(url, {
            method: 'get',
            mode:'cors',
            headers:{
                'authorization':token
            }
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETEXAMINELLIST',
                data:res     
            });
        })
    }
}
//获取已通过审核的列表
export const getAdoptList = () =>{
    return (dispatch)=>{
        let url = address + '/userstep/reviewedtrue';
        fetch(url, {
            method: 'get',
            mode:'cors',
            headers:{
                'authorization':token
            }
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETADOPTLIST',
                data:res     
            });
        })
    }
}

//获取未通过审核的列表
export const getFailedList = () =>{
    return (dispatch)=>{
        let url = address + '/userstep/reviewedfalse';
        fetch(url, {
            method: 'get',
            mode:'cors',
            headers:{
                'authorization':token
            }
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETFAILEDLIST',
                data:res     
            });
        })
    }
}

//获取审核详情列表
export const getViewDetail = (id) =>{
    return (dispatch)=>{
        let url = address + '/userstep/reviewing/'+id;
        fetch(url, {
            method: 'get',
            mode:'cors',
            headers:{
                'authorization':token
            },
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETVIEWDETAILS',
                data:res     
            });
        })
    }
}
//获取点赞人数
export const getLikeNumber = (name) =>{
    return (dispatch)=>{
        let url = address + '/admin/showGreatNum';
        fetch(url, {
            method: 'POST',
            mode:'cors',
            headers:{
                'authorization':token
            },
            body:name
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETLIKENUMBER',
                data:res     
            });
        })
    }
}
//获取收藏人数
export const getCollectNumber = (name) =>{
    return (dispatch)=>{
        let url = address + '/admin/showCollectNum';
        fetch(url, {
            method: 'POST',
            mode:'cors',
            headers:{
                'authorization':token
            },
            body:name
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETCOLLECTNUMBER',
                data:res     
            });
        })
    }
}


//获取文章内容
export const getArticleContent = (urlPath)=>{
    return (dispatch)=>{
        let url = urlPath;
        fetch(url, {
            method: 'get',
            mode:'cors',
        })
        .then(res => res.text())
        .then(res => {
            dispatch({
                type:'GETARTCONTENT',
                data:res     
            });
        })
    }
}
//获取文章列表
export const getArticleList = () =>{
    return (dispatch)=>{
        let url = address + '/usepassage';
        fetch(url, {
            method: 'get',
            mode:'cors'
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETARTICLELIST',
                data:res     
            });
        })
    }
}
//获取App列表
export const getApplist = () =>{
    return (dispatch)=>{
        let url =address + '/useapp';
        fetch(url, {
            method: 'GET',
            mode:'cors',
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETAPPLIST',
                data:res     
            });
        })
    }
}
//获取功能列表
export const getFunList = (name) =>{
    return (dispatch)=>{
        let url = address + `/useapp/${name}`;
        fetch(url, {
            method:'GET',
            mode:'cors',
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETAPPFUNLIST',
                data:res     
            });
        })
    }
}
//获取步骤列表
export const getStepList = (name) =>{
    return (dispatch)=>{
        let appPath = name.split('/')[3];
        let funName = name.split('/')[4];
        let url = address + `/useapp/${appPath}?type=${funName}`;
        fetch(url, {
            method: 'GET',
            mode:'cors',
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETFUNSTEPLIST',
                data:res    
            });
        })
    }
}


//获取用户列表
export const getUserInfoList = () =>{
    return (dispatch)=>{
        let url = address + `/admin/getUsers`;
        fetch(url, {
            method: 'GET',
            mode:'cors',
            headers:{
                'authorization':token
            }
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETUSERINFOLIST',
                data:res    
            });
        })
    }
}
//获取意见反馈列表
export const getFeedbackList = () =>{
    return (dispatch)=>{
        let url = address + `/admin/showSuggestions`;
        fetch(url, {
            method: 'GET',
            mode:'cors',
            headers:{
                'authorization':token
            }
        })
        .then(res => res.json())
        .then(res => {
            dispatch({
                type:'GETFEEDBACKLIST',
                data:res    
            });
        })
    }
}
